home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgramD2.iso / Visual Database / Visual BASIC 5.0 (Ent. Edition) / Vb5ent Extractor.EXE / VB / SAMPLES / PGUIDE / OPTIMIZE / GRAPHICS.FRM (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1996-09-16  |  10.4 KB  |  309 lines

  1. VERSION 5.00
  2. Begin VB.Form Graphics 
  3.    BorderStyle     =   3  'Fixed Dialog
  4.    Caption         =   "Graphics"
  5.    ClientHeight    =   6585
  6.    ClientLeft      =   1980
  7.    ClientTop       =   1905
  8.    ClientWidth     =   7620
  9.    BeginProperty Font 
  10.       Name            =   "MS Sans Serif"
  11.       Size            =   8.25
  12.       Charset         =   0
  13.       Weight          =   700
  14.       Underline       =   0   'False
  15.       Italic          =   0   'False
  16.       Strikethrough   =   0   'False
  17.    EndProperty
  18.    ForeColor       =   &H80000008&
  19.    Icon            =   "GRAPHICS.frx":0000
  20.    LinkTopic       =   "Form1"
  21.    LockControls    =   -1  'True
  22.    MaxButton       =   0   'False
  23.    MinButton       =   0   'False
  24.    PaletteMode     =   1  'UseZOrder
  25.    ScaleHeight     =   439
  26.    ScaleMode       =   3  'Pixel
  27.    ScaleWidth      =   508
  28.    ShowInTaskbar   =   0   'False
  29.    Tag             =   "Resource"
  30.    Begin VB.PictureBox Picture1 
  31.       Align           =   1  'Align Top
  32.       Height          =   1335
  33.       Left            =   0
  34.       ScaleHeight     =   1275
  35.       ScaleWidth      =   7560
  36.       TabIndex        =   6
  37.       TabStop         =   0   'False
  38.       Top             =   0
  39.       Width           =   7620
  40.       Begin VB.CommandButton cmdRedraw 
  41.          Caption         =   "&Redraw"
  42.          Default         =   -1  'True
  43.          BeginProperty Font 
  44.             Name            =   "MS Sans Serif"
  45.             Size            =   8.25
  46.             Charset         =   0
  47.             Weight          =   400
  48.             Underline       =   0   'False
  49.             Italic          =   0   'False
  50.             Strikethrough   =   0   'False
  51.          EndProperty
  52.          Height          =   492
  53.          Left            =   5400
  54.          TabIndex        =   2
  55.          Top             =   480
  56.          Width           =   1812
  57.       End
  58.       Begin VB.ListBox lstRedrawType 
  59.          BackColor       =   &H00FFFFFF&
  60.          BeginProperty Font 
  61.             Name            =   "MS Sans Serif"
  62.             Size            =   8.25
  63.             Charset         =   0
  64.             Weight          =   400
  65.             Underline       =   0   'False
  66.             Italic          =   0   'False
  67.             Strikethrough   =   0   'False
  68.          EndProperty
  69.          Height          =   675
  70.          Left            =   120
  71.          TabIndex        =   0
  72.          Top             =   120
  73.          Width           =   2475
  74.       End
  75.       Begin VB.Frame Frame1 
  76.          Caption         =   "Graphic"
  77.          BeginProperty Font 
  78.             Name            =   "MS Sans Serif"
  79.             Size            =   8.25
  80.             Charset         =   0
  81.             Weight          =   400
  82.             Underline       =   0   'False
  83.             Italic          =   0   'False
  84.             Strikethrough   =   0   'False
  85.          EndProperty
  86.          Height          =   1095
  87.          Left            =   2850
  88.          TabIndex        =   1
  89.          Top             =   30
  90.          Width           =   1455
  91.          Begin VB.OptionButton optGraphicType 
  92.             Caption         =   "Metafile"
  93.             BeginProperty Font 
  94.                Name            =   "MS Sans Serif"
  95.                Size            =   8.25
  96.                Charset         =   0
  97.                Weight          =   400
  98.                Underline       =   0   'False
  99.                Italic          =   0   'False
  100.                Strikethrough   =   0   'False
  101.             EndProperty
  102.             Height          =   255
  103.             Index           =   1
  104.             Left            =   120
  105.             TabIndex        =   4
  106.             Top             =   555
  107.             Width           =   1095
  108.          End
  109.          Begin VB.OptionButton optGraphicType 
  110.             Caption         =   "Bitmap"
  111.             BeginProperty Font 
  112.                Name            =   "MS Sans Serif"
  113.                Size            =   8.25
  114.                Charset         =   0
  115.                Weight          =   400
  116.                Underline       =   0   'False
  117.                Italic          =   0   'False
  118.                Strikethrough   =   0   'False
  119.             EndProperty
  120.             Height          =   255
  121.             Index           =   0
  122.             Left            =   120
  123.             TabIndex        =   3
  124.             Top             =   255
  125.             Value           =   -1  'True
  126.             Width           =   975
  127.          End
  128.       End
  129.       Begin VB.Label lblTime 
  130.          Appearance      =   0  'Flat
  131.          BackColor       =   &H80000005&
  132.          BackStyle       =   0  'Transparent
  133.          Caption         =   "Time:"
  134.          BeginProperty Font 
  135.             Name            =   "MS Sans Serif"
  136.             Size            =   9.75
  137.             Charset         =   0
  138.             Weight          =   700
  139.             Underline       =   0   'False
  140.             Italic          =   0   'False
  141.             Strikethrough   =   0   'False
  142.          EndProperty
  143.          ForeColor       =   &H00800000&
  144.          Height          =   255
  145.          Left            =   5400
  146.          TabIndex        =   7
  147.          Top             =   120
  148.          Width           =   1815
  149.       End
  150.       Begin VB.Image imgMetafile 
  151.          Appearance      =   0  'Flat
  152.          Height          =   915
  153.          Left            =   135
  154.          Picture         =   "GRAPHICS.frx":030A
  155.          Top             =   405
  156.          Visible         =   0   'False
  157.          Width           =   915
  158.       End
  159.       Begin VB.Image imgBitmap 
  160.          Appearance      =   0  'Flat
  161.          Height          =   1005
  162.          Left            =   1170
  163.          Picture         =   "GRAPHICS.frx":0540
  164.          Top             =   285
  165.          Visible         =   0   'False
  166.          Width           =   1080
  167.       End
  168.    End
  169.    Begin VB.PictureBox Container 
  170.       Align           =   1  'Align Top
  171.       Appearance      =   0  'Flat
  172.       BackColor       =   &H80000005&
  173.       ForeColor       =   &H80000008&
  174.       Height          =   5535
  175.       Left            =   0
  176.       ScaleHeight     =   367
  177.       ScaleMode       =   3  'Pixel
  178.       ScaleWidth      =   506
  179.       TabIndex        =   5
  180.       TabStop         =   0   'False
  181.       Top             =   1335
  182.       Width           =   7620
  183.       Begin VB.Image cell 
  184.          Appearance      =   0  'Flat
  185.          BorderStyle     =   1  'Fixed Single
  186.          Height          =   1035
  187.          Index           =   0
  188.          Left            =   0
  189.          Picture         =   "GRAPHICS.frx":18AA
  190.          Top             =   240
  191.          Width           =   1110
  192.       End
  193.    End
  194. Attribute VB_Name = "Graphics"
  195. Attribute VB_GlobalNameSpace = False
  196. Attribute VB_Creatable = False
  197. Attribute VB_TemplateDerived = False
  198. Attribute VB_PredeclaredId = True
  199. Attribute VB_Exposed = False
  200. Option Explicit
  201. ' Take a look at the various ReSizeCells general procedures.
  202. ' Also, try changing the Stretch property of the Cell control.
  203. Dim iFormLoad As Integer
  204. Private Sub cmdRedraw_Click()
  205.     ReDraw
  206. End Sub
  207. Private Sub Form_Load()
  208.   Dim i As Integer
  209.   ' Signals no paint on form load.
  210.   iFormLoad = True
  211.   PosForm Me
  212.   For i = 1 To 63
  213.     Load cell(i)
  214.     cell(i).Visible = True
  215.   Next i
  216.   'Load the listbox
  217.   lstRedrawType.AddItem "Naive"
  218.   lstRedrawType.AddItem "Using Variables"
  219.   lstRedrawType.AddItem "With Each Image Invisible"
  220.   lstRedrawType.AddItem "Making Container Invisible"
  221.   lstRedrawType.ListIndex = 0
  222. End Sub
  223. Private Sub Form_Resize()
  224. ' Don't do anything when minimized
  225.     If WindowState <> 1 And iFormLoad <> True Then
  226.         Container.Height = ScaleHeight - Container.Top
  227.         ReDraw
  228.     End If
  229.     ' Reset the flag so we redraw next time.
  230.     iFormLoad = False
  231. End Sub
  232. Private Sub optGraphicType_Click(Index As Integer)
  233. Dim i As Integer
  234.     If Index Then
  235.         cell(0).Picture = imgMetafile.Picture
  236.     Else
  237.         cell(0).Picture = imgBitmap.Picture
  238.     End If
  239.     Screen.MousePointer = 11
  240.     ' Make container invisible while loading pictures.
  241.     ' Try commenting out those lines to see speed difference.
  242.     Container.Visible = False
  243.     For i = 1 To 63
  244.         cell(i).Picture = cell(0).Picture
  245.     Next i
  246.     Container.Visible = True
  247.     Screen.MousePointer = 0
  248. End Sub
  249. Private Sub ReDraw()
  250. Dim start, Finish
  251.     Screen.MousePointer = 11
  252.     start = Timer
  253.     Select Case lstRedrawType.ListIndex
  254.         Case 0
  255.             ReSizeCells0
  256.         Case 1
  257.             ReSizeCells1
  258.         Case 2
  259.             ReSizeCells2
  260.         Case 3
  261.             ReSizeCells3
  262.     End Select
  263.     Finish = Timer
  264.     lblTime = "Time: " + Format(Finish - start, "0.000") + " Sec."
  265.     Screen.MousePointer = 0
  266. End Sub
  267. Private Sub ReSizeCells0()
  268. ' Naive code to resize and redraw graphic cells.
  269. Dim i As Integer
  270.     For i = 0 To 63
  271.         cell(i).Move (i Mod 8) * (Container.ScaleWidth \ 8), (i \ 8) * (Container.ScaleHeight \ 8), Container.ScaleWidth \ 8, Container.ScaleHeight \ 8
  272.     Next i
  273. End Sub
  274. Private Sub ReSizeCells1()
  275. ' Improved code: replace constant expressions with variables
  276. ' and use variables instead of properties.
  277. Dim i As Integer, cellwidth As Integer, cellheight As Integer
  278.     cellwidth = Container.ScaleWidth \ 8
  279.     cellheight = Container.ScaleHeight \ 8
  280.     For i = 0 To 63
  281.         cell(i).Move (i Mod 8) * cellwidth, (i \ 8) * cellheight, cellwidth, cellheight
  282.     Next i
  283. End Sub
  284. Private Sub ReSizeCells2()
  285. ' More improved code: make each Image control invisible
  286. ' during the move; this improves paint speed.
  287. Dim i As Integer, cellwidth As Integer, cellheight As Integer
  288.     cellwidth = Container.ScaleWidth \ 8
  289.     cellheight = Container.ScaleHeight \ 8
  290.     For i = 0 To 63
  291.         cell(i).Visible = False
  292.         cell(i).Move (i Mod 8) * cellwidth, (i \ 8) * cellheight, cellwidth, cellheight
  293.         cell(i).Visible = True
  294.     Next i
  295. End Sub
  296. Private Sub ReSizeCells3()
  297. ' Fastest code: make container invisible while moving and sizing
  298. ' all contained Images.  Only one paint occurs.
  299. Dim i As Integer, cellwidth As Integer, cellheight As Integer
  300.     Container.Visible = False
  301.     cellwidth = Container.ScaleWidth \ 8
  302.     cellheight = Container.ScaleHeight \ 8
  303.     For i = 0 To 63
  304.         cell(i).Move (i Mod 8) * cellwidth, (i \ 8) * cellheight, cellwidth, cellheight
  305.     Next i
  306.     Container.Visible = True
  307.     'Container.Refresh
  308. End Sub
  309.